from utils.wrapper import *
import re

# 验证预约表单数据合法
def check_user_order(request):

    # 获取留言用户名
    user_name = post(request, "user_name")
    # 获取留言用户联系方式
    user_tel = post(request, "user_tel")
    # 获取预约项目
    user_order = post(request,"user_order")
    # 获取预约时间
    user_time = post(request,"user_time")
    # 获取备注
    user_msg = post(request,"user_msg")


    re_tel = re.match("^1[3458]\d{9}$", user_tel, re.I)

    flag = True


    if  user_order == "0":
        add_message(request, "error_order", "您没有选择预约项目~")
        flag = False

    if  len(user_time) == 0:
        add_message(request, "error_time", "您没有选择预约时间~")
        flag = False

    if len(user_name) > 10 or user_name == "":
        add_message(request, "error_name", "用户名格式不正确")
        flag = False

    if (not re_tel) or user_tel == "":
        add_message(request, "error_tel", "手机号格式不正确~~")
        flag = False

    if len(user_msg) > 160:
        add_message(request, "error_msg", "备注长度不能超过160~~")
        flag = False

    return flag

